//
//  HttpResponse.h
//  EZC_Library
//
//  Created by ellzu on 14-9-23.
//  Copyright (c) 2014年 ellzu. All rights reserved.
//

#ifndef __EZC_Library__HttpResponse__
#define __EZC_Library__HttpResponse__

#include <stdio.h>
#include <string>
#include "EZTally/EZTallyObject.h"
#include <vector>

namespace EZHttp {
    
    class HttpRequest;
    class HttpRequestPlatformInterface;
    
    class HttpResponse : public EZTally::EZTallyObject
    {
    public:
        HttpResponse();
    protected:
        virtual ~HttpResponse();
        
    
    public:
        /**
         return 服务器返回状态码
         **/
        int responseCode();
        
        /**
         服务器返回http头信息
         **/
        std::vector<std::string>* headers();
        
        /**
         对应的请求实例
         **/
        HttpRequest *request();
        
        /**
         内容长度
         **/
        size_t contentLen();
        /**
         己下载长度
         **/
        size_t contentCurLen();
        /**
         下载的数据
         **/
        unsigned char* content();
        /**
         复制下载的数据
         **/
        size_t copyContent(unsigned char*buffer,size_t bufferLen,size_t offset);
        
    protected:
        
        friend class HttpRequest;
        friend class HttpRequestPlatformInterface;
        
        void setRequest(HttpRequest *request);
        HttpRequest *_request;
        
        void setResponseCode(int code);
        int _responseCode;
        
        void setContentLen(size_t len);
        size_t _contentLen;
        
        std::vector<std::string> _headers;
        
        size_t _writeBufferOil;
        size_t _bufferLen;
        unsigned char *_buffer;
        void setBufferLen(size_t len);
        size_t appendBuffer(unsigned char* buffer,size_t bufferLen);
        
        
        FILE *_fileHandel;
        FILE* tryOpenFileHandel();
        void closeFileHandel();
        
    };
}
#endif /* defined(__EZC_Library__HttpResponse__) */
